#!/usr/bin/env bash

tomcat="401 Unauthorized"
jenkins="http://eclipse.org/jetty"
driver="WebDriver Hub"


ip=$1
port=$2
path=$3


# todo   how about save title ?
cmd="curl -s --connect-timeout 10 -m 8 $ip:$port$path"
#echo $cmd
res=`eval $cmd`
#echo $res



if [[ "$res" =~ "$tomcat" ]]
then
    server="tomcat"
elif [[ "$res" =~ "$jenkins" ]]
then
    server="jenkins"
elif [[ "$res" =~ "$driver" ]]
then
    server='driver'
elif [[ "$res" = "" ]]
then
    server="-2"
else
    server='1'
fi

echo $server
#echo $server >> s




req="curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
\"ip\": \"$ip\" ,\
\"server\": \"$server\" ,\
\"port\":\"$port\"
}' 'http://www.luohao.work/target/reportService'"
eval $req